package com.kingyea.mobilepolice.apimanage.serverapimonitor.controller;

import com.kingyea.mobilepolice.apimanage.serverapimonitor.service.ServerApiMonitorService;
import com.kingyea.mobilepolice.apimanage.sysvo.bean.AllCondition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Optional;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ServerApiMonitor 控制层
 * @date Created in 2018-05-19 14:08:21
 */
@RequestMapping(value = "/serverApiMonitor")
@RestController
public class ServerApiMonitorController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServerApiMonitorController.class);

    @Autowired
    private ServerApiMonitorService serverApiMonitorService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(path = "/search", method = RequestMethod.POST)
    public Object search(@RequestBody AllCondition condition) throws Exception {
        Date startTime = Optional.ofNullable(condition.getStartTime()).orElse(new Date());
        startTime.setHours(0);
        startTime.setMinutes(0);
        startTime.setSeconds(0);
        Date endTime = Optional.ofNullable(condition.getEndTime()).orElse(new Date());
        endTime.setHours(23);
        endTime.setMinutes(59);
        endTime.setSeconds(59);
        condition.setStartTime(startTime);
        condition.setEndTime(endTime);
        return serverApiMonitorService.search(condition);
    }
//
//    /**
//     * 通过ID查找对象
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public Object detail(@PathVariable Integer id) throws Exception {
//        return serverApiMonitorService.getById(id);
//    }
//
//    /**
//     * 创建
//     * @param serverApiMonitor
//     * @return
//     */
//    @RequestMapping(method = RequestMethod.POST)
//    public Object create(@RequestBody ServerApiMonitor serverApiMonitor) throws Exception {
//        return serverApiMonitorService.save(serverApiMonitor);
//    }
//
//    /**
//     * 更新
//     * @param serverApiMonitor
//     * @return
//     */
//    @RequestMapping(method = RequestMethod.PUT)
//    public Object update(@RequestBody ServerApiMonitor serverApiMonitor) throws Exception {
//        return serverApiMonitorService.update(serverApiMonitor);
//    }
//
//    /**
//     * 删除
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public Object delete(@PathVariable Integer id) throws Exception {
//        return serverApiMonitorService.deleteById(id);
//    }

}
